/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

/**
 *
 * @author vimi Administrator
 */
public class RandomUtil {

    public static int retRandNum(int N)
    {
        double randNum = Math.random();

        double deltaStep = 1.0/((double) N+1.0);

        //System.out.println("retRandNum: deltaStep "+deltaStep);

        int i=0;
        double StepValue = 0;


        while (StepValue<=1.0)
        {
                       
            if (randNum>= StepValue && randNum<=StepValue+deltaStep)
            {
                //System.out.println("retRandNum: i "+i);
                return i;
            }

            StepValue += deltaStep ;
            i++;
            
        }

        return 0;
    }


    public static int retRandNum(int N, int exceptI)
    {
        double randNum = Math.random();

        double deltaStep = 1.0/((double) N+1.0);



        int i=0;
        double StepValue = 0;


        while (StepValue<=1.0)
        {

            if (randNum>= StepValue && randNum<=StepValue+deltaStep && i!=exceptI)
            {
                //System.out.println("retRandNum: i "+i);
                return i;
            }

            StepValue += deltaStep ;
            i++;
        }

        return 0;
    }

    /*
    public static int retRandNum(int N, int exceptI)
    {
        double randNum = Math.random();

        for (int i=0;i<=N;i++)
        {
            double rateNum = i/N;
            if (randNum<=rateNum && i!=exceptI) return i;
        }

        return 0;
    }

    */


    public static int retRandNum(int N, int [] exceptIs)
    {
        double randNum = Math.random();

        double deltaStep = 1.0/((double) N+1.0);



        int i=0;
        double StepValue = 0;


        while (StepValue<=1.0)
        {
            boolean inArray = false;

            for (int except:exceptIs)
            {
              if (i==except) inArray = true;
            }

            if (randNum>= StepValue && randNum<=StepValue+deltaStep && !inArray)  return i;


            StepValue += deltaStep ;
            i++;
        }

        return 0;
        
    }

    /*
    public static int retRandNum(int N, int [] exceptIs)
    {
        double randNum = Math.random();

        for (int i=0;i<=N;i++)
        {
            double rateNum = i/N;

            boolean inArray = false;

            for (int except:exceptIs)
            {
              if (i==except) inArray = true;
            }

            if (randNum<=rateNum && !inArray) return i;
        }

        return 0;
    }
     *
     */
    
}
